<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
    <title>抽取专家查看</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="${ctx}/lib/js/html5shiv.min.js"></script>
        <script src="${ctx}/lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
							
    <section class="content-header">
        <h1>抽取专家查看</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">专家抽取管理</a></li>
            <li class="active"><a href="#">抽取专家查看</a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
               <div class="form-inline">
                   <div class="form-group form-group-xs">
						<label>所属项目：</label> 
						<select class='form-control' id="projectId"
							style="width: 250px;" onchange="setValueOfProj()"  disabled="disabled">
							<option value="">请选择</option>
							<c:forEach items="${projectList}" var="project">
								<option value="${project.projId}">${project.name}</option>
							</c:forEach>
						</select>
					</div>
                    <!-- <div class="form-group form-group-xs">
                        <label for="searchPharCode">专家姓名：</label>
                        <input class="form-control" type="text" id="name" placeholder="专家姓名" maxlength="100" />
                    </div>                
                    <button type="button" class="btn btn-success btn-sm" onclick="search();">查&nbsp;询</button> -->
                </div> 
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
        
        <div class=" box box-warning bottongroup">
            <label class="btn btn-default btn-sm" onclick="editPassword()">分配账户</label>
               <c:if test="${defaultProjId == null}">
             	<a href="toExtractExpertList.html" class="btn btn-default btn-sm">返&nbsp;回</a>
             </c:if>
        </div>
	      <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" >
	            <div class="modal-dialog">
	                <div class="modal-content">
	                    <div class="modal-header bg-primary">
	                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	                        <h5 class="modal-title" id="exampleModalLabel">默认密码设置</h5>
	                    </div>
	                    <div class="modal-body">
			                  <form id="formSubmit"  action="allocateAcct.html">
			                    <div class="form-group form-group-xs">
			                        <label for="recipient-name" class=" control-label">设置专家登录默认密码：</label>
			                        <input type="password" class="form-control" id="password" name="password" placeholder="密码">
			                        <input type="hidden" id="projId" name="projId" value="${projId}"/>
			                    </div>
			                    <div class="form-group form-group-xs">
					        		<label for="newpassword" class="col-sm-2 text-right"><i class="fa fa-exclamation-circle fa-lg" style="color:#dd4b39;"></i>&nbsp;<span style="color:#dd4b39;font-weight:600">提示：</span></label>					        
						    		<div class="col-sm-10 text-left" style="color:#dd4b39">
						           		 密码长度为6-12位且包含有大写字母、小写字母、数字和特殊字符('~!@#$%^&*()_+`\-={}:'<>?,.\/')组成
						    		</div>
				        		 </div>
			                 </form>
	            		</div>
	              <div class="modal-footer">
	              	   <button type="button" onclick="allocateAcct();" class="btn btn-primary btn-sm">确&nbsp;定</button>
	              </div>
	            </div>
	         </div>
	     </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    
    <script type="text/javascript">
    
    var colorList = [];//用来保存主grid每一行原来的颜色
    
       //分配账户
    	function allocateAcct(){
    		var password = $("#password").val();
    		var parn = /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{6,12}$/;
    	     if (password == null || password == "") {
    	         $.HN.message.alert("请输入默认密码！", "提示信息", "warn");
    	         return;
    	     } else if (password.length < 6) {
    	         $.HN.message.alert("密码长度为6-18位！", "提示信息", "warn");
    	         return;
    	     } else if (!(parn.test(password))) {
    	    	 $.HN.message.alert("密码至少有一个大写字母、一个小写字母、数字和一个特殊字符('~!@#$%^&*()_+`\-={}:'<>?,.\/')组成", "消息", "warn");
    	         return;
    	     }
    		$.HN.message.confirm("确定分配账户吗？", '', '').on(function (e) {
                if (e) {
		    		$("#formSubmit").ajaxSubmit({
		    			dataType : "json",
		    			timeout: 10000,
		    			success : function(result) {
		    				if (result.success) {
		    					$.HN.message.alert(result.msg||" ", "消息", "success")
		    					$('#exampleModal').modal('hide');
		    					search();
		    				} else {
		    					$.HN.message.alert(result.msg || "", "消息", "error");
		    					$('#exampleModal').modal('hide');
		    				}
		    			}
		    		});	
                }
             });
    		$("#password").val("");
    	}
       function editPassword(){
    	   var projectId = $("#projectId").val();
	   		if(null == projectId || "" == projectId){
	   			$.HN.message.alert("请选择项目", "消息", "w")
	   			return;
	   		}
    	   $('#exampleModal').modal({
               keyboard: true
           });
       }
    	function back(){
    		document.location.href="toExpertExtractRuleList.html";
    	}
    	//查询
    	function search(page) {
    		var name = $("#name").val();
    		var projectId = $("#projectId").val();
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{"name":name, "projId":projectId },
    	        page : (page || 1)
    	    }).trigger("reloadGrid"); //重新载入  
    	}
    	function setValueOfProj(){
    		var projectId = $("#projectId").val();
    		$("#projId").val(projectId)
    	}
        $(function () {
        	
               $("#gridlist").jqGrid({
                url: "getExpertExtractListRuleList.html?projId=${projId}",
                mtype: "post",
                datatype: "json",
                autowidth: true,
                shrinkToFit:true,
                height: 330,
                colNames: [
                     '规则编码',
                    '是否大输液',
					'抽取状态',
					'抽取时间',
					'抽取组数',
					'状态',
					'hospTypeList'
					
                ],
                colModel: [
					{ name: 'ruleCode', width: 100, align:"center", sortable: false},
                    { name: 'infusion', width: 80,align:"center", sortable: false,
                    	formatter:function(val,opts,rowdata){
                    		if(rowdata.infusion==1){
                    			return "是";
                    		}else if(rowdata.infusion==0){
                    			return "否";
                    		}else {
                    			return "";
                    		}
                    	}
                    },
                    
                    { name: 'execStatus', width: 60, align: 'center', sortable: false,
                    	formatter : function(val, opts, rowdata) {
                    		var strSta = "";
                    		if(rowdata.execStatus == 1){
                    			strSta += "已抽取";
                    		}else if(rowdata.execStatus == 0){
                    			strSta += "未抽取";
                    		}
                    		return strSta;
                    	}
                    },
                    { name: 'execDatetime', width: 110, align:"center", sortable: false},
                    { name: 'extractNum', width: 110, align:"center", sortable: false},
                    { name: 'status', width: 60, align: 'center', sortable: false,
                    	formatter : function(val, opts, rowdata) {
                    		var strSta = "";
                    		if(rowdata.status == 1){
                    			strSta += "启用";
                    		}else if(rowdata.status == 0){
                    			strSta += "停用";
                    		}
                    		return strSta;
                    	}
                    },
                    { name: 'hospTypeList', width: 60,hidden:true, align: 'center', sortable: false,
                    	formatter : function(val, opts, rowdata) {
                    		var strSta = "";
                    		if(rowdata.hospTypeList.length>0){
                		    		for(var i = 0;i<rowdata.hospTypeList.length;i++){
                		    			strSta+= rowdata.hospTypeList[i].dicName+":"+rowdata.hospTypeList[i].expertRate+"%   ";
                		    		}
                    		}else{
                    			strSta += "医疗机构类型等比例抽取";
                    		}
                    		return strSta;
                    	} 
                    },
                ],
                rowNum: 0,
                rownumbers: true,
                caption: "规则列表",
                jsonReader: {
                    id: "ruleId"
                },
                subGrid: true,
                subGridOptions: {
                    "plusicon"  : "ui-icon-circle-plus",
                    "minusicon" : "ui-icon-circle-minus",
                    //"openicon"  : "ui-icon-carat-1-sw",
            		// load the subgrid data only once
            		// and the just show/hide
            		"reloadOnExpand" : false,
            		// select the row when the expand column is clicked
            		"selectOnExpand" : false
            	},
            	subGridRowExpanded: function(subgrid_id, row_id) {
            		//恢复主表的行背景颜色
            		var rowIds = $("#gridlist").getDataIDs(); 
            		for(var i = 0;i<rowIds.length;i++){
            			$("#"+rowIds[i]).css("background-color",colorList[i].color);
            		}
            		
            		var subgrid_table_id;
            		subgrid_table_id = subgrid_id+"_t";
            		$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table>");
            		$("#"+subgrid_table_id).jqGrid({
            			url:"getExpertTypeRuleList.html?projId=${projId}&ruleId="+row_id,
            			mtype: "post",
            			width:900,
                        datatype: "json",
            			colNames: ['专家名称','专家类型','医疗机构分类','组号'],
            			colModel: [
            				{name:"name",index:"name",align:"center",width:200,sortable: false},
            				{name:"expertTypeName",index:"expertTypeName",width:200,align:"center",sortable: false},
            				{name:"dicName",index:"dicName",width:200,align:"center",sortable: false},
            				{name:"groupNum",index:"groupNum",width:70,align:"center",sortable:false}
            			],
            		   	rowNum:0,
            		   	rownumbers: true,
            		    height: '100%',
            		    caption: "被抽取专家列表",
            		    
            		    gridComplete:function(){
            		    }
            		    
            		});
            		
            		//删除没用的标签
            		$($("#"+row_id).next('.ui-subgrid').children()[0]).remove();
            		$($("#"+row_id).next('.ui-subgrid').children()[0]).remove();
            		//使子表居中
            		$("#gbox_gridlist_"+row_id+"_t").width($("#gview_gridlist").width()-26);
    		    	$("#gview_gridlist_"+row_id+"_t").css("margin","0 auto");
    		    	//改变子表题头背景颜色
    		    	$($("#gview_gridlist_"+row_id+"_t").children()[0]).css("background-color","#00a65a");
    		    	$($("#gview_gridlist_"+row_id+"_t").children()[0]).css("border-color","#008d4c");
    		    	
    		    	//修复主表展开行下一行的上边框
    		    	for(var i = 0;i<colorList.length;i++){
             			if(row_id==colorList[i].id){
             				if(colorList[i+1]){
             					$("#"+colorList[i+1].id).css("border-top","1px solid #cecece");
                 				break;
             				}
             			}
             		}
    		    	var rowData = $("#gridlist").jqGrid('getRowData',row_id);
        	        $("#"+subgrid_table_id).setCaption(rowData.hospTypeList);
    		    	
    		    	$(window).resize(function(){
    		    		$("#gbox_gridlist_"+row_id+"_t").width($("#gview_gridlist").width()-26);
        		    	$("#gview_gridlist_"+row_id+"_t").css("margin","0 auto");
    		    	});
            		
            	},
            	subGridRowColapsed: function(subgrid_id, row_id) { 
            	
            	},
            	loadComplete: function(){
            		colorList = [];
            		var rowIds = $("#gridlist").getDataIDs(); 
            		for(var i = 0;i<rowIds.length;i++){
            			colorList.push({"id":rowIds[i],"color":$("#"+rowIds[i]).css("background-color")});
            		}
            		//$(".sgcollapsed").click();
            		
    		    },
    		    gridComplete:function(){
    		    	//未抽取的规则去除展开的+号
    		    	var rowIds = $("#gridlist").getDataIDs(); 
    		    	for(var i = 0;i<rowIds.length;i++){
    		    		var rowData = $("#gridlist").jqGrid('getRowData',rowIds[i]);
    		    		if(rowData.execStatus!="已抽取"){
    		    			$($("#"+rowIds[i]).children()[1]).children().remove();
    		    			$($("#"+rowIds[i]).children()[1]).removeClass("sgcollapsed");
    		    			$($("#"+rowIds[i]).children()[1]).css("cursor","default");
    		    		}
    		    	}
    		    	
    		    }
            	
            });   
            
            
            //判断是否显示大输液列
            ${infusion==null?"//":infusion?"//":""}$("#gridlist").hideCol("infusion");
            
            $(window).trigger("resize");
            
          //设置列表题头
            $("#gridlist").setCaption($("#projectId  option:checked").html()||"规则列表");
        });
        $(document).ready(function(){
        	var ruleId = "${ruleId}";
            if(ruleId !=null || ruleId !=""){
            	$("#allocat").html("返回");
            }
        })
        
        $("#projectId").val("${projId}");
        
    </script>
</body>
</html>

